<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Poll/classes/PhpFox_ComponentMemberPolls.class.php, $Author:  $ */



/** Component for showing list of member polls
 *
 * @version $Id: PhpFox_ComponentMemberPolls.class.php 297 2008-02-07 15:05:58Z phpfoxsv $
 * @package module.poll
 */
class PhpFox_Mod_Poll_ComponentMemberPolls extends BaseComponent
{
    function process()
    {
    	App::membersOnly();

		$oAccountService = &App::getModuleService('Account', 'Account');

        $oPollItem = &$this->_oModule->getItem('Poll');
        /* @var $oPollItem PhpFox_Mod_Poll_ItemPoll */
        $oPollService = &$this->_oModule->getService('Poll');
        /* @var $oPollService PhpFox_Mod_Poll_ServicePoll */
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oTpl = &$this->_oModule->getTemplate();
        $oUrl = &App::getUrl();
        $oReq = &App::getRequest();
        App::loadClass('Pager');

        $oSecurityService->checkPerm('poll', array('full', 'read_only'));
        $oSecurityService->checkAccess('poll');
        $sUser = $oSecurityService->getCurrentUserLogin();

        $iPage = $oReq->getInt('page', 1);
        if ($iPollId = $oReq->getInt('delete'))
        {
            $oSecurityService->checkPerm('poll', 'full');
            $oPollItem->load($iPollId);
            if ($oPollItem->aData['user'] == $sUser)
            {
                $oPollService->deletePoll($iPollId);
                $oAccountService->changeUserInfo($oSecurityService->getCurrentUser(), 'poll', -1);
            }
            App::gotoUrl('public.account.myitems.poll', array('page' => $iPage));
        }
        $iPageSize = App::getParam('public.member_polls_count');
        $sSort = 'time DESC';
        $aCond = array();
        $aCond['user'] = '= "'.$sUser.'"';
        list($aItems, $iCnt) = $oPollItem->getList($aCond, $iPage, $iPageSize, $sSort);
        $oPager = &new Pager($iCnt, $iPage, $iPageSize);
        $iFrom = $oPager->getOffset($iPage, $iPageSize);
        $iTo = (($iFrom + $iPageSize) > $iCnt) ? $iCnt : ($iFrom + $iPageSize);

        $oTpl->assign(array(
            'aItems'           => $aItems,
        	'iFrom'            => ($iCnt) ? ($iFrom + 1) : 0,
        	'iTo'              => $iTo,
        	'iCnt'             => $iCnt,
        	'aPaging'          => ($iCnt) ? $oPager->getInfo($oUrl) : '',
        	'sMonthDateFormat' => App::getParam('format.monthdate%'),
        ));
        return $oTpl->fetch('MemberPolls.html');
    }
}
?>